﻿<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="apple-touch-fullscreen" content="YES" />
<meta name="format-detection" content="telephone=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="pragram" content="no-cache" />

<link href="css/style.css" type="text/css" rel="stylesheet"/>

<title>扭蛋机</title>
<!--移动端版本兼容 -->
<script type="text/javascript">
    var phoneWidth =  parseInt(window.screen.width);
    var phoneScale = phoneWidth/640;
    var ua = navigator.userAgent;
    if (/Android (\d+\.\d+)/.test(ua)){
        var version = parseFloat(RegExp.$1);
        // andriod 2.3
        if(version>2.3){
            document.write('<meta name="viewport" content="width=640, minimum-scale = '+phoneScale+', maximum-scale = '+phoneScale+', target-densitydpi=device-dpi">');
        // andriod 2.3以上
        }else{
            document.write('<meta name="viewport" content="width=640, target-densitydpi=device-dpi">');
        }
        // 其他系统
    } else {
        document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">');
    }
    //微信去掉下方刷新栏
    if(RegExp("MicroMessenger").test(navigator.userAgent)){
        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            WeixinJSBridge.call('hideToolbar');
        });
    }
</script>

    <script src="js/jquery1.8.3.min.js"></script>
    <!--<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.0.js"></script>-->
 


</head>
<body>

<div class="niu_danji">
	<!-- 标题 -->
	<div class="game_title"></div>
	<!--机器-->
	<div class="game_qu">
    	<!--go-->
        <div class="game_go"></div>
        <div class="wdjifen">你还有<span class="count-chang">0</span>次机会</div>
    </div>
    
    <!--球-->
    <div class="dan_gund">
        <span  class="qiu_1 diaol_1"></span>
        <span  class="qiu_2 diaol_2"> </span>
        <span  class="qiu_3 diaol_3"></span>
        
        <span  class="qiu_4 diaol_4"></span>
        <span  class="qiu_5 diaol_5"></span>
        <span  class="qiu_6 diaol_6"></span>>
        
        <span  class="qiu_7 diaol_7"></span>
        <span  class="qiu_8 diaol_8"></span>
        
        
        <span  class="qiu_9 diaol_9"></span>
        <span  class="qiu_10 diaol_10"></span> 
        <span  class="qiu_11 diaol_11"></span>   
               
    </div>

     <!--中奖掉落-->
   <div class="medon"><img src="images/mendong.png"/></div>
   <div class="zjdl ">
   		<span></span>
   </div>
   <div class="rule_list">
		<p class="title"><span class="pic-icon"></span>游戏活动规则<span class="pic-icon"></span></p>
		<div class="rule_content">  </div>
	</div>
    
   </div>




<!--中奖 获得一等奖-->
<div class="zonj_zezc none" id="jianpin_one">
	<div class="jpzs aiqiyi tc_anima">
    	<em><img src="images/close.png" style="width: 30px;" /></em>
        <p style="font-size: 34px;text-align: center;padding: 20px 0 47px;color: #ec6882;">恭喜你！中奖了！</p>
        <div style="text-align: center; position: relative;">
        	<img src="images/coupon.png" alt="" style="width: 280px;">
			<p class="price" style="position: absolute;bottom: 44px;color: #ec6882;font-size: 24px;left: 120px;">￥<span style="font-size: 40px;">50</span></p>
			<p class="title" style="position: absolute;bottom: 24px;left: 123px;">冰点脱毛</p>
	        <p class="big-title" style="display:none;position: absolute;bottom: 46px;left: 109px;font-size: 24px;color: #ec6882;">冰点脱毛</p>
        </div>
    </div></div>



<!--没有中奖-->
<div class="zonj_zezc none" id="jianpin_kong">
	<div class="jpzs aiqiyi tc_anima">
    	<em><img src="images/close.png" style="width: 30px;"/></em>
    	<div style="text-align: center;padding-top: 60px;">
    		<img src="images/kong.png" alt="" style="width: 130px;">
    	</div>
        <p class="tishi" style="text-align: center;padding-top: 20px;font-size: 34px;color: #757575;">
        	很遗憾 你没有中奖
        </p>
    </div>
</div>


<!--积分不足-->
<div class="zonj_zezc none" id="no_jifeng">
	<div class="jpzs aiqiyi tc_anima">
    	<em><img src="images/close.png" style="width: 30px;"/></em>
        <h2>
        	对不起，次数不足！
        </h2>
    </div>
</div>
<script>
	
$(document).ready(function(e) {
	// wx.miniProgram.navigateTo({url: '/path/to/page'})
    var urlPath = window.location.protocol+"//"+document.domain;
    var gameId=getQueryString('id');
    var token=getQueryString('token').replace(/%3d/g,'=');
    var orgId=getQueryString('orgId');
	getDetail(gameId,orgId);
	getCount(gameId,token);
	// $("#jianpin_one").show();
	//一等奖 关闭
	$("#jianpin_one em img").click(function(){
		$("#jianpin_one").hide();
		}
	);					
	//没有中奖 关闭
	$("#jianpin_kong em img").click(function(){
		$("#jianpin_kong").hide();
		}
	);			
	//积分不足 关闭
	$("#no_jifeng em img").click(function(){
		$("#no_jifeng").hide();
		}
	);		
		
var score=0;
var changeitem=true;
$(".game_go").click(function(){
	if(changeitem==true){
       changeitem=false;
       if(score<=0){
		for(i=1;i<=11;i++){
				$(".qiu_"+i).removeClass("wieyi_"+i);
			}
			$("#no_jifeng").show();
		}else{
			draw()
		}
	}
	
});
	
	
function draw(){
	var number =Math.floor(4*Math.random()+1);  

	for(i=1;i<=11;i++){
			$(".qiu_"+i).removeClass("diaol_"+i);
			$(".qiu_"+i).addClass("wieyi_"+i);
		};
			
	setTimeout(function (){
		for(i=1;i<=11;i++){
		$(".qiu_"+i).removeClass("wieyi_"+i);
		}
	},1100);	
	setTimeout(function(){
		switch(number){
			case 1:$(".zjdl").children("span").addClass("diaL_one");break;
			case 2:$(".zjdl").children("span").addClass("diaL_two");break;
			case 3:$(".zjdl").children("span").addClass("diaL_three");break;
			case 4:$(".zjdl").children("span").addClass("diaL_four");break;
		}
		$(".zjdl").removeClass("none").addClass("dila_Y");
		getResult(gameId,token,orgId);
		// setTimeout(function (){
		// 	switch(number){
		// 		case 1:$("#jianpin_one").show();break;
		// 		case 2:$("#jianpin_two").show();break;
		// 		case 3:$("#jianpin_three").show();break;
		// 		case 4:$("#jianpin_kong").show();break;
		// 	}
		// },900);
	},1100)
	
	//取消动画
	setTimeout(function (){
			$(".zjdl").addClass("none").removeClass("dila_Y");
			$(".wdjifen .count-chang").html(score);
			$(".zjdl").children("span").removeAttr('class');
			
		},2500)
			
}	
function getDetail(id,orgId){
	 $.ajax({
         type: "GET",
         url: urlPath+"/activity/marketing/gameDetails",
         data: {marketingId:id,orgId:orgId},
         dataType: "json",
         success: function(data){
         	// if(data.success){
         		$(".rule_content").html(data.data.gameExplain);
         	// }
         }         
     });
}
function getCount(id,token){
	 $.ajax({
         type: "GET",
         url: urlPath+"/activity/marketing/residue",
         data: {marketingId:id,token:token},
         headers: { 'content-type': 'application/x-www-form-urlencoded', "source": "shop", "token": token },
         dataType: "json",
         success: function(data){
         	if(data.success){
         		score=data.data;
         		$(".wdjifen .count-chang").html(data.data);
         	}
         }         
     });
}
function getResult(id,token,orgId){
	 $.ajax({
         type: "GET",
         url: urlPath+"/activity/marketing/result",
         data: {marketingId:id,token:token,orgId:orgId},
         headers: { 'content-type': 'application/x-www-form-urlencoded', "source": "shop", "token": token },
         dataType: "json",
         success: function(data){
             score-=1;
         	if(data.success){
         	    if(data.data.price){
                    $("#jianpin_one .title").show();
                    $("#jianpin_one .big-title").hide();
                    $("#jianpin_one .price span").html(data.data.price);
                    $("#jianpin_one .title").html(data.data.title);
                }else{
                    $("#jianpin_one .title").hide();
                    $("#jianpin_one .big-title").show();
                    $("#jianpin_one .price").html('');
                    $("#jianpin_one .big-title").html(data.data.title);
                }
         		$("#jianpin_one").show();

                
         	}else{
         		$("#jianpin_kong .tishi").html(data.errorMessage);
         		$("#jianpin_kong").show();
         	}
         	changeitem=true;
         }         
     });
}
 function getQueryString(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) {
        return decodeURIComponent(r[2]);
      }
      return null;
    }
});


</script>


</body>
</html>
